class Solution {//leetcode24——两两交换链表中的节点
public:
    ListNode* swapPairs(ListNode* head) {
        if(head==nullptr||head->next==nullptr) return head;
        ListNode* newhead=new ListNode(0);
        newhead->next=head;
        ListNode* prev=newhead,*cur=prev->next,*next=cur->next,*next_next=next->next;
        while(cur&&next){
            prev->next=next;
            next->next=cur;
            cur->next=next_next;
            prev=cur;
            cur=next_next;
            if(cur) next=cur->next;
            if(next) next_next=next->next;
        }
        ListNode* ret=newhead->next;
        delete newhead;
        return ret;
    }
};